/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package todomanager.MODEL;

import java.io.IOException;
import java.util.ArrayList;
import java.util.ResourceBundle;

import todomanager.data.ITask;
import todomanager.data.TodoData;
import todomanager.io.TodoXMLWriter;

/**
 * A Model for interacting with TodoData objects.
 * @author jonasbirgersson, gihoon Kim
 */
public class TodoManagerModel {

    private TodoData data;
    //private 

    public void addTask(ITask task) {
        data.addTask(task); 
        TodoXMLWriter writer = new TodoXMLWriter();
        writer.exportTodo(data.getDataAsArrayList());
    }

    public void addTodoData(TodoData data) {
        this.data = data;
        //TODO Save data to XML file.
    }
    
    public void editTodoData(TodoData data) {
        this.data = data;
        //TODO Save data to XML file.
    }
    
    public void deleteTask(int id) throws IOException{
    	TodoXMLWriter writer = new TodoXMLWriter();
    	data.deleteTask(id);
    	writer.deletetask(id);
    }

    public Object[][] getTodoData(ResourceBundle lang) {

        return data.getTasksAsObject(lang);
    }
    
    public ArrayList getPendingTasks(int days){
    	return data.getPendingTasks(days);
    }
    
    
    public void editTask(ITask iTask, ArrayList help) throws IOException {
    	data.editTask(iTask, help);
    	TodoXMLWriter writer = new TodoXMLWriter();
       // edit.EditListForWrite(iTask,help);
    	writer.EditListForWrite(iTask, help);
       // writer.exportTodoEdit(task, help);*/
    }

	public void deleteTaskByName(String selectedTaskName) {
		data.deleteTaskByName(selectedTaskName);
		TodoXMLWriter writer = new TodoXMLWriter();
		writer.exportTodo(data.getDataAsArrayList());
		
	}
}
